package com.indexingsystem.boss.common;

import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.apache.log4j.PropertyConfigurator;

import com.indexingsystem.boss.logback.LogCvt;
import com.indexingsystem.boss.utils.DateUtil;

public class ScpConstants{
    
    public static final String IMAGE = "png,jpg,jpeg";
    
    public static ScpConfig SCPCONFIG;
    
    public static HashMap<String,String> mapPros;
    
    public final static  Properties table = new Properties();

    static{
        mapPros = new HashMap<String, String>();
        try {
            table.load(LogCvt.class.getClassLoader().getResourceAsStream("scp.properties"));
            PropertyConfigurator.configure(table);
        } catch (IOException e) {
            e.printStackTrace();
        }
        Enumeration<?> en = table.propertyNames();
        String key;
        while (en.hasMoreElements()) {
            key = (String) en.nextElement();
            mapPros.put(key, table.getProperty(key));
        }
        
        if(get("scp.port")!=null){
            SCPCONFIG = new ScpConfig(get("scp.host"),Integer.parseInt(get("scp.port")),get("scp.user"),get("scp.password"));
        }else{
            SCPCONFIG = new ScpConfig(get("scp.host"),get("scp.user"),get("scp.password"));
        }
    }
    
    public static String getString(String key) {
        return table.getProperty(key);
    }
    
    public static Map<String,String> getAll(){
        Map<String, String> map = new HashMap<String, String>((Map) table);
        return map;     
    }
    
    
    public static String get(String key){
        return mapPros.get(key);
    }
    
    
    public static String getImgLocalUrl(){
        return System.getProperty("java.io.tmpdir");
    }
    
    public static String getImgRemoteUrl(){
        return get("merchant.image.remote") + DateUtil.getCurDate().substring(0,6) + "/";
    }
    
    public static String getScpImgUploadPath(){
        return get("scp.uploadpath") + DateUtil.getCurDate().substring(0,6) + "/" ;
    }
    
    public static String getScpQrcodeUploadPath(){
        return get("scp.qrcodeuploadpath") + DateUtil.getCurDate().substring(0,6) + "/" ;
    }
    
    public static String getScpQrcodeImgPath(){
        return get("scp.qrcodeimgpath") + DateUtil.getCurDate().substring(0,6) + "/" ;
    }
    
    
    public static String getQrocdImgPath(){
        return get("scp.qrodepath");
    }
    
    public static String getBaseImgPath(){
        return get("image.path");
    }
    public static String getFontPath(){
        return get("font.path");
    }
}